﻿using IBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace WebYuekaoUI.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkController : ControllerBase
    {
        public WorkController(IWorkBll bll,ILogger<WorkController> logger)
        {
            Bll = bll;
            Logger = logger;
        }

        public IWorkBll Bll { get; }
        public ILogger<WorkController> Logger { get; }

        /// <summary>
        /// 职员信息添加
        /// </summary>
        /// <param name="work">表名</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost] 
        public Task<int> Tian(Work work)
        {
            try//异常处理
            {
                Logger.LogInformation("记录日志");
                return Bll.Tian(work);
            }
            catch (Exception)
            {
                Logger.LogError("记录错误日志");
                throw;
            }
        }
        /// <summary>
        /// 职员信息查询功能
        /// </summary>
        /// <param name="name">职员姓名</param>
        /// <param name="typess">职员类别</param>
        /// <returns></returns>
        [HttpGet]
        public IQueryable<Work> Xian(string? name, string? typess)
        {
            try//异常处理
            {
                Logger.LogInformation("记录日志");
                return Bll.Xian(name, typess);
            }
            catch (Exception)
            {
                Logger.LogError("记录错误日志");
                throw;
            }
        }
        /// <summary>
        /// 记录错误日志
        /// </summary>
        [HttpGet]
        public void Err()
        {
            try//异常处理
            {
                Logger.LogInformation("记录日志");
                int j = 0;
                int k = 0;
                int l = j / k;
            }
            catch (Exception)
            {
                Logger.LogError("记录错误日志");
                throw;
            }
        }
    }
}
